class Solution:
    def numberOfSets(self, n: int, k: int) -> int:
        MOD = 10**9 + 7
        dp = [[0] * (k + 1) for _ in range(n + 1)]
        sums = [0 for _ in range(k + 1)]
        for i in range(1, n + 1):
            dp[i][1] = ((i - 1)**2 + (i - 1)) // 2
            if i - 1 <= k:
                dp[i][i - 1] = 1
        for i in range(2, n + 1):
            stop = min(i, k + 1)
            for j in range(2, stop):
                dp[i][j] = dp[i - 1][j]
                sums[j - 1] += dp[i - 1][j - 1]
                dp[i][j] += sums[j - 1]
                dp[i][j] %= MOD

        return dp[n][k]
